home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / CoreGateway / StaticLetter.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  7.1 KB  |  349 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        StaticLetter.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __STATICLETTER__
  15. #include "StaticLetter.h"
  16. #endif
  17.  
  18. #ifndef __RECIPIENT__
  19. #include "Recipient.h"
  20. #endif
  21.  
  22. #ifndef __UTILITIES__
  23. #include "Utilities.h"
  24. #endif
  25.  
  26. #ifndef    __RESOURCES__
  27. #include "Resources.h"
  28. #endif
  29.  
  30. #ifndef __TOOLUTILS__
  31. #include "ToolUtils.h"
  32. #endif
  33.  
  34. #ifndef    __STRING__
  35. #include "String.h"
  36. #endif
  37.  
  38. #pragma segment TStaticLetter
  39.  
  40. /***********************************|****************************************/
  41.  
  42. TStaticLetter::TStaticLetter 
  43. (
  44.     TRecipient* to,
  45.     TRecipient* from,
  46.     const TRString& subject,
  47.     const TRString& content 
  48. ):
  49.     TLetter (),
  50.     fTo ( to ),
  51.     fFrom ( from ),
  52.     fSubject ( subject ),
  53.     fContent ( content ),
  54.     fTemplate ( nil )
  55. {
  56. }
  57.  
  58. /***********************************|****************************************/
  59.  
  60. TStaticLetter::TStaticLetter 
  61. (
  62.     TRecipient* to,
  63.     TRecipient* from,
  64.     const TRString& subject,
  65.     const TRString& content ,
  66.     const ResType templateType,
  67.     short templateID
  68. ):
  69.     TLetter (),
  70.     fTo ( to ),
  71.     fFrom ( from ),
  72.     fSubject ( subject ),
  73.     fContent ( content ),
  74.     fTemplate ( nil )
  75. {
  76.     LoadTemplate ( templateType, templateID );
  77. }
  78.  
  79. /***********************************|****************************************/
  80.  
  81. TStaticLetter::~TStaticLetter ()
  82. {
  83.     if ( fTemplate )
  84.         ::ReleaseResource ( fTemplate );
  85. }
  86.  
  87. /***********************************|****************************************/
  88.  
  89. Boolean
  90. TStaticLetter::LoadTemplate ( const ResType templateType, short templateID )
  91. {
  92.     if ( fTemplate )
  93.         ::ReleaseResource ( fTemplate );
  94.  
  95.     fTemplate = ::GetResource ( templateType, templateID );
  96.     
  97.     return fTemplate != nil;
  98. }
  99.  
  100. /***********************************|****************************************/
  101.  
  102. Boolean
  103. TStaticLetter::SetTemplateItem ( unsigned short zeroBasedItemIndex, const char* replaceString )
  104. {
  105.     Boolean result = false;
  106.     
  107.     if ( fTemplate && zeroBasedItemIndex <= 9 && replaceString )
  108.     {
  109.         Byte targetString [ 2 ] = { '^', '0' };
  110.         targetString [ 1 ] += (Byte) zeroBasedItemIndex;
  111.         result = ::Munger ( fTemplate, 0, targetString, 2, (Ptr) replaceString, ::strlen ( replaceString ) ) >= 0;
  112.     }
  113.     
  114.     return result;
  115. }
  116.  
  117. /***********************************|****************************************/
  118.  
  119. Boolean
  120. TStaticLetter::GetLetterID ( BLJLetterID& ) const
  121. {
  122.     return false;
  123. }
  124.  
  125. /***********************************|****************************************/
  126.  
  127. Boolean
  128. TStaticLetter::GetReplyID ( BLJLetterID& ) const
  129. {
  130.     return false;
  131. }
  132.  
  133. /***********************************|****************************************/
  134.  
  135. Boolean
  136. TStaticLetter::GetConversationID ( BLJLetterID& ) const
  137. {
  138.     return false;
  139. }
  140.  
  141. /***********************************|****************************************/
  142.  
  143. Boolean
  144. TStaticLetter::GetSendTimeStamp (BLJTime&) const
  145. {
  146.     return false;
  147. }
  148.  
  149. /***********************************|****************************************/
  150.  
  151. Boolean
  152. TStaticLetter::GetLetterPriority (LetterPriority& priority) const
  153. {
  154.     priority = highPriority;
  155.     return true;
  156. }
  157.  
  158. /***********************************|****************************************/
  159.  
  160. Boolean
  161. TStaticLetter::GetSubject (RString& subject) const
  162. {
  163.     fSubject.GetString ( subject, kRStringMaxBytes );
  164.     return true;
  165. }
  166.  
  167. /***********************************|****************************************/
  168.  
  169. Boolean
  170. TStaticLetter::IsLetterAutoForwarded (Boolean& yesItIs) const
  171. {
  172.     yesItIs = false;
  173.     return true;
  174. }
  175.  
  176. /***********************************|****************************************/
  177.  
  178. Boolean
  179. TStaticLetter::IsLetterAutoReply (Boolean& yesItIs) const
  180. {
  181.     yesItIs = false;
  182.     return true;
  183. }
  184.  
  185. /***********************************|****************************************/
  186.  
  187. Boolean
  188. TStaticLetter::CanLetterBeAutoForwarded (Boolean& yesItCan) const
  189. {
  190.     yesItCan = false;
  191.     return true;
  192. }
  193.  
  194. /***********************************|****************************************/
  195.  
  196. unsigned short
  197. TStaticLetter::GetRecipientCount(RecipientTypeSet type) const
  198. {
  199.     return type == fromRecipient || type == toRecipient ? 1 : 0;
  200. }
  201.  
  202. /***********************************|****************************************/
  203.  
  204. TRecipient*
  205. TStaticLetter::GetRecipient (RecipientTypeSet type, unsigned short index ) const
  206. {
  207.     if ( index != 1 )
  208.         return nil;
  209.     else if ( type == fromRecipient )
  210.         return fFrom;
  211.     else if ( type == toRecipient )
  212.         return fTo;
  213.     else    
  214.         return nil;
  215. }
  216.  
  217. /***********************************|****************************************/
  218.  
  219. Boolean
  220. TStaticLetter::GetRecipientStatus(RecipientTypeSet type, unsigned short index, RecipientStatusSet& status ) const
  221. {
  222.     TRecipient* recipient = GetRecipient ( type, index );
  223.     
  224.     if ( recipient )
  225.     {
  226.         status = recipient->GetStatus (  );
  227.         return true;
  228.     }
  229.     else
  230.     {
  231.         return false;
  232.     }
  233. }
  234.  
  235. /***********************************|****************************************/
  236.  
  237. Boolean
  238. TStaticLetter::SetRecipientStatus(RecipientTypeSet type, unsigned short index, RecipientStatusSet status )
  239. {
  240.     TRecipient* recipient = GetRecipient ( type, index );
  241.     
  242.     if ( recipient )
  243.     {
  244.         return recipient->SetStatus ( status );
  245.     }
  246.     else
  247.     {
  248.         return false;
  249.     }
  250. }
  251.  
  252. /***********************************|****************************************/
  253.  
  254. unsigned short
  255. TStaticLetter::GetUnknownRecipientCount() const
  256. {
  257.     return 0;
  258. }
  259.  
  260. /***********************************|****************************************/
  261.  
  262. Boolean
  263. TStaticLetter::DeliveryReceiptRequested(Boolean &yesItIs) const
  264. {
  265.     yesItIs = true;
  266.     return true;
  267. }
  268.  
  269. /***********************************|****************************************/
  270.  
  271. Boolean
  272. TStaticLetter::NonDeliveryReportRequested (Boolean& yesItIs) const
  273. {
  274.     yesItIs = true;
  275.     return true;
  276. }
  277.  
  278. /***********************************|****************************************/
  279.  
  280. unsigned long TStaticLetter::GetContentTypeCount ( ) const
  281. {
  282.     return 1;
  283. }
  284.  
  285. /***********************************|****************************************/
  286.  
  287. OSType TStaticLetter::GetContentType ( unsigned long i ) const
  288. {
  289.     if ( ( i == 1 ) )
  290.         return 'TEXT';
  291.     
  292.     return '\?\?\?\?';
  293. }
  294.  
  295. /***********************************|****************************************/
  296.  
  297. unsigned long TStaticLetter::GetSegmentCount ( OSType contentType ) const
  298. {
  299.     return 1;    // content only
  300. }
  301.  
  302. /***********************************|****************************************/
  303.  
  304. Boolean
  305. TStaticLetter::GetSegmentInfo(OSType contentType, unsigned long index, BLJLetterBlockType& blockType, long& blockLength) const
  306. {
  307.     if ( ( contentType == 'TEXT' ) && ( index == 1 ) )
  308.     {
  309.         blockType.type = 'TEXT';
  310.         blockType.creator = 'BLoJ';
  311.  
  312.         blockLength = fTemplate ? ::SizeResource ( fTemplate ) : 0;
  313.         return true;
  314.     }
  315.     else
  316.     {
  317.         return false;
  318.     }
  319. }
  320.  
  321. /***********************************|****************************************/
  322.  
  323. Boolean
  324. TStaticLetter::GetSegmentData ( OSType contentType, unsigned long index, unsigned long offset, void* buffer, long& count ) const
  325. {
  326.     if ( ( contentType == 'TEXT' ) && ( index == 1 ) )
  327.     {
  328.         count = fTemplate ? ::SizeResource ( fTemplate ) : 0;
  329.         
  330.         if ( offset < count )
  331.         {    
  332.             ::BlockMove ( *fTemplate + offset, buffer, count - offset );
  333.         }
  334.         else
  335.         {
  336.             count = 0;
  337.         }
  338.         
  339.         return true;
  340.     }
  341.     else
  342.     {
  343.         count = 0;
  344.         return false;
  345.     }
  346. }
  347.  
  348. /***********************************|****************************************/
  349.